package com.augurit.wf.common.dao;


import org.springframework.stereotype.Repository;

import com.augurit.common.base.dao.BaseDao;
import com.augurit.wf.app.notice.convert.NoticeConverter;
import com.augurit.wf.app.notice.web.form.NoticeForm;
import com.augurit.wf.common.entity.Notice;

/**
 * 公告板DAO类
 */
@Repository
public class NoticeDao extends BaseDao<Notice, Long> {
	
	/**
	 * 获取公告板form对象
	 * @param id
	 * @return
	 */
	public NoticeForm getForm(Long id){
		if(id == null)
			return null;
		Notice entity = this.get(id);
		return NoticeConverter.convertToForm(entity);
	}
	
	/**
	 * 保存公告
	 * @param form
	 */
	public void save(NoticeForm form){
		if(form != null){
			Notice entity = null;
			
			//准备VO对象
			if(form.getId() != null){
				entity = this.get(form.getId());
			}
			else{
				entity = new Notice();
			}
			//属性值转换
			NoticeConverter.convertToEntity(form, entity);
			
			//保存
			this.save(entity);
			this.flush();
			
			//回填ID属性值
			form.setId(entity.getId());
		}
	}
	
}
